<!--
 * @Description:筋斗云小项目
 * @Author: Sun
 * @Date: 2019-07-01 20:05:50
 * @LastEditors: Sun
 * @LastEditTime: 2019-07-16 22:42:13
 -->
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>筋斗云小项目</title>
	<style>
		* {
			margin: 0;
			padding: 0;
		}

		ul {
			list-style: none
		}

		body {
			background-color: #000;
		}

		.nav {
			width: 800px;
			height: 42px;
			background-color: floralwhite;
			margin: 100px auto;
			border-radius: 5px;
			position: relative;
		}

		.cloud {
			width: 83px;
			height: 42px;
			position: absolute;
			top: 0;
			left: 0;
			background: url("./img/1.jpg") no-repeat center center;
			background-size: cover;
		}

		.nav ul {
			position: absolute;
			top: 0;
			left: 0;
			z-index: 1;
		}

		.nav li {
			float: left;
			width: 83px;
			height: 42px;
			line-height: 42px;
			text-align: center;
			color: #000;
			cursor: pointer;
		}
	</style>
	<script>
		window.onload = function () {
			var cloud = document.getElementById("cloud")
			var nav = document.getElementById("nav")
			let leader = 0,
					target = 0;
			var current=0;
			let timer = null
			var lis = nav.children[1].children;
			for (let index = 0; index < lis.length; index++) {
				const element = lis[index];
				element.onmouseover = function () {
					target = this.offsetLeft
				}
				element.onmouseout = function () {
					target = current
				}
				element.onclick=function(){
					target = this.offsetLeft
					current=this.offsetLeft
				}
			}

			clearInterval(timer)
			timer = setInterval(() => {
				leader = leader + (target - leader) / 10
				cloud.style.left = leader + "px"
			}, 30)
		}
	</script>
</head>

<body>
	<div class="nav" id="nav">
		<span class="cloud" id="cloud"></span>
		<ul>
			<li>1</li>
			<li>2</li>
			<li>3</li>
			<li>4</li>
			<li>5</li>
			<li>6</li>
			<li>7</li>
			<li>8</li>
		</ul>
	</div>
</body>

</html>